<template>
  <div>
    <input placeholder="输入关键字搜索" v-model="search"/>
    <table class="my-table">
      <thead>
        <tr>
          <th>就诊日期</th>
          <th>医生姓名</th>
          <th>诊断结果</th>
          <th>处方信息</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <HmTable
          v-for="item in list"
          :key="item.uname"
          :time="item.time"
          :uname="item.uname"
          :result="item.result"
          :msg="item.msg"
          :operate="item.operate"
        ></HmTable>
      </tbody>
    </table>
  </div>
</template>

<script>
import HmTable from './components/HmTable.vue';
export default {
    components: {
    HmTable,
  },

  data() {
    return {
      search:'',
      list: [
        {
          time: '2022-01-12',
          uname: '王五',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
        {
          time: '2022-01-12',
          uname: '张三',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
        {
          time: '2022-01-12',
          uname: '李四',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
      ],
      list1: [
        {
          time: '2022-01-12',
          uname: '王五',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
        {
          time: '2022-01-12',
          uname: '张三',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
        {
          time: '2022-01-12',
          uname: '李四',
          result: '流感',
          msg: '感冒药',
          operate: '详情',
        },
      ],
    };
  },
  methods: {},
  mounted() {},
  watch: {
    search(value){   
      if(value){
        console.log(value);
      this.list=this.list.filter((item)=>{return item.uname===value})
      console.log(this.list);
      }else{
        this.list=this.list1
      } 
    }
  },

};
</script>

<style scoped>
.my-table {
  border-collapse: collapse;
  width: 100%;
}

.my-table td,
.my-table th {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
}

.my-table th {
  background-color: #f2f2f2;
}
</style>
